<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API 请求示例</title>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
    <style>
        /* 自定义样式 */
        body {
            font-family: Arial, sans-serif;
        }
        #responseBox {
            height: 120px;
            resize: none;
        }
    </style>
</head>
<body class="bg-light">

<div class="container py-4">
    <div class="row justify-content-center">
        <div class="col-lg-12 col-md-12">
            <div class="card shadow-sm mb-12">
                <div class="card-header bg-primary text-white">
                    <h5 class="card-title">请求后端接口</h5>
                </div>
                <div class="card-body">
                    <!-- 参数输入框 -->
                    <div class="mb-6">
                        <label for="paramInput" class="form-label">请输入昵称：</label>
                        <input type="text" class="form-control" id="nickname" name="nickname">
                        <label for="paramInput" class="form-label">请输入cooickie：</label>
                        <textarea type="text" class="form-control" id="paramInput" name="paramInput">
                        </textarea>
                    </div>

                    <!-- 提交按钮 -->
                    <button id="submitButton" class="btn btn-primary w-100">提交请求</button>
                </div>
            </div>

            <!-- 显示返回信息的文本框 -->
            <div class="card shadow-sm mt-4">
                <a href="http://119.3.239.188:56085/sailing/list.html" target="_blank">
                    <div class="card-header bg-secondary text-white">
                        <h5 class="card-title">运行日志</h5>
                    </div>
                </a>
                <a href="http://119.3.239.188:56085/sailing/index1.html" target="_blank">
                    <div class="card-header bg-secondary text-white">
                        <h5 class="card-title">实时刷歌</h5>
                    </div>
                </a>
                <div class="card-header bg-secondary text-white">
                    <h5 class="card-title">响应内容</h5>
                </div>
                <div class="card-body">
                    <textarea id="responseBox" class="form-control h-100" rows="5" readonly></textarea>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        // 绑定按钮点击事件
        $('#submitButton').click(function () {
            // 获取输入框中的参数值
            var param = $('#paramInput').val();
            var param1 = $('#nickname').val();

            // 发送AJAX请求到后端接口（这里假设接口地址是/api/endpoint）
            $.ajax({
                url: 'http://119.3.239.188:56085/sailing/runJob',
                method: 'POST',
                data: {paramInput: param,nickname:param1},
                success: function (response) {
                    // 在响应成功时，将返回的信息显示在文本框中
                    $('#responseBox').val(response);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    // 在发生错误时，可以处理错误信息
                    console.error('请求失败：', textStatus, ', 错误：', errorThrown);
                    $('#responseBox').val('请求失败，请检查网络或后端接口状态');
                }
            });
        });
    });
</script>

</body>
</html>
